﻿package mortal.game.view.chat.chatPrivate
{
    import Message.Game.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import mortal.game.cache.*;
    import mortal.game.scene3D.layer3D.utils.*;

    public class ChatManager extends Object
    {
        private static var _aryWindow:Vector.<ChatPrivateWindow> = new Vector.<ChatPrivateWindow>;
        private static var _guildWindow:ChatGuildWindow;

        public function ChatManager()
        {
            return;
        }// end function

        public static function addMessage(param1:ChatData) : void
        {
            var _loc_2:* = getWindowBySEntityId(param1.chatWindowEntityId);
            var _loc_3:* = param1.sChatMsg;
            var _loc_4:* = param1.chatWindowName;
            var _loc_5:* = param1.date;
            var _loc_6:* = param1.content;
            var _loc_7:* = param1.chatColor;
            var _loc_8:* = param1.chatFromPlayerName;
            if (_loc_3 && _loc_2 && _loc_4 == _loc_3.fromPlayer.name && EntityUtil.equal(param1.chatWindowEntityId, param1.sChatMsg.fromPlayer.entityId))
            {
                _loc_2.updatePlayerMsg(_loc_3.fromPlayer);
            }
            if (_loc_2)
            {
                _loc_2.addChatItem(param1);
                if (_loc_2.isHide)
                {
                }
            }
            return;
        }// end function

        public static function addGuildWindow() : ChatGuildWindow
        {
            var _loc_1:* = Cache.instance.role.entityInfo.guildId;
            if (!_guildWindow)
            {
                _guildWindow = new ChatGuildWindow();
            }
            _guildWindow.guildId = _loc_1;
            return _guildWindow;
        }// end function

        public static function addGuildMessage(param1:ChatData) : void
        {
            if (_guildWindow)
            {
                _guildWindow.addChatItem(param1);
                if (_guildWindow.isHide)
                {
                }
            }
            return;
        }// end function

        public static function addWindow(param1:SMiniPlayer) : ChatPrivateWindow
        {
            var _loc_2:* = getWindowBySEntityId(param1.entityId);
            if (!_loc_2)
            {
                _loc_2 = new ChatPrivateWindow(param1);
                _aryWindow.push(_loc_2);
            }
            return _loc_2;
        }// end function

        public static function exitGuild() : void
        {
            if (_guildWindow)
            {
                _guildWindow.clearMsg();
                ChatManager.removeChatWindow(_guildWindow);
            }
            return;
        }// end function

        public static function removeChatWindow(param1:ChatBaseWindow) : void
        {
            param1.hide();
            return;
        }// end function

        public static function getWindowByName(param1:String) : ChatPrivateWindow
        {
            var _loc_2:ChatPrivateWindow = null;
            for each (_loc_2 in _aryWindow)
            {
                
                if (_loc_2.getChatPlayerName() == param1)
                {
                    return _loc_2;
                }
            }
            return null;
        }// end function

        public static function getWindowBySEntityId(param1:SEntityId) : ChatPrivateWindow
        {
            var _loc_2:ChatPrivateWindow = null;
            if (!param1)
            {
                return null;
            }
            for each (_loc_2 in _aryWindow)
            {
                
                if (EntityUtil.equal(_loc_2.getChatPlayerEntityId(), param1))
                {
                    return _loc_2;
                }
            }
            return null;
        }// end function

        public static function getWindowByWindowUId(param1:String) : ChatBaseWindow
        {
            var _loc_2:ChatPrivateWindow = null;
            if (_guildWindow && EntityUtil.toString(_guildWindow.getChatPlayerEntityId()) == param1)
            {
                return _guildWindow;
            }
            for each (_loc_2 in _aryWindow)
            {
                
                if (EntityUtil.toString(_loc_2.getChatPlayerEntityId()) == param1)
                {
                    return _loc_2;
                }
            }
            return null;
        }// end function

        public static function updateMiniPlayer(param1:SMiniPlayer) : void
        {
            var _loc_2:* = getWindowBySEntityId(param1.entityId);
            if (_loc_2)
            {
                _loc_2.updatePlayerMsg(param1);
            }
            return;
        }// end function

        public static function get guildWindow() : ChatGuildWindow
        {
            return _guildWindow;
        }// end function

    }
}
